package com.demohomework.homeworkdemo.mapper;

import com.demohomework.homeworkdemo.pojo.Course;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CourseMapper {
    @Insert("INSERT INTO course( name,credit,teacher_id,create_at) VALUES( #{name}, #{credit},#{teacherId},now())")
    void add(Course course);


    @Select("SELECT * FROM course")
    List<Course> list(Integer id);

    @Select("SELECT * FROM course WHERE id = #{id}")
    Course findId(Integer id);

    @Update("UPDATE course SET name = #{name}, credit = #{credit}, teacher_id = #{teacherId}, is_open = #{isOpen},update_at = now() WHERE id = #{id}")
    void update(Course course);

    @Delete("DELETE FROM course WHERE id = #{id}")
    void delete(Integer id);

    @Select("SELECT * FROM course WHERE teacher_id = #{teacherId}")
    List<Course> selectByTeacherId(Integer teacherId);
}
